package com.culturalCenter.dataCenter.mapper.user;

import com.culturalCenter.dataCenter.customEntity.CustomRole;
import com.culturalCenter.dataCenter.entity.user.Role;
import com.culturalCenter.dataCenter.mapper.base.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    /**
     * 通过用户id查询
     *
     * @param userId 用户id
     *
     * @return
     */
    List<Role> queryByUserId(@Param("userId") String userId);

    /**
     * 获取需要鉴权的url
     */
    @Select("SELECT roleCode AS roleCode,tr.interfaceUrl AS roleUrl FROM `cdc_role_rule` rr \n" +
            "LEFT JOIN cdc_role r ON rr.roleId=r.id\n" +
            "LEFT JOIN cdc_rule tr ON rr.ruleId=tr.id WHERE tr.interfaceUrl IS NOT NULL")
    List<CustomRole> findRoleUrl();

}
